package org.example.executor;

import org.example.config.Configuration;
import org.example.mapping.BoundSql;
import org.example.mapping.MappedStatement;
import org.example.session.ResultHandler;
import org.example.session.RowBounds;

import java.sql.SQLException;
import java.util.List;

public abstract class BaseExecutor implements Executor {

    protected final Configuration configuration;
    protected Executor wrapper;

    public BaseExecutor(Configuration configuration) {
        this.wrapper = this;
        this.configuration = configuration;
    }

    @Override
    public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
        BoundSql boundSql = ms.getSqlSource().getBoundSql(parameter);
        return doQuery(ms, parameter,rowBounds, resultHandler, boundSql);
    }

    protected abstract <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
            throws SQLException;
}
